﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports System.ComponentModel

''' <summary>
''' This class stores the setting for the ftp upload
''' </summary>
''' <remarks></remarks>
Public Class ClassFTPSetting
#Region "Fields"
    Private _host As String
    Private _name As String
    Private _userName As String
    Private _password As String
    Private _port As Integer
    Private _remotePath As String
    Private _passive As Boolean
    Private _externalHost As String
#End Region
#Region "Properties"
    <CategoryAttribute("FTP"), Description("Host Address for FTP server")> _
    Public Property Host() As String
        Get
            Return _host
        End Get
        Set(ByVal value As String)
            _host = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("External Address To Access The File")> _
    Public Property ExternalHost() As String
        Get
            Return _externalHost
        End Get
        Set(ByVal value As String)
            _externalHost = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Name for these settings")> _
    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Use Passive Mode")> _
    Public Property Passive() As Boolean
        Get
            Return _passive
        End Get
        Set(ByVal value As Boolean)
            _passive = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Password For FTP Account")> _
    Public Property Password() As String
        Get
            Return _password
        End Get
        Set(ByVal value As String)
            _password = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Port For FTP Account")> _
    Public Property Port() As Integer
        Get
            Return _port
        End Get
        Set(ByVal value As Integer)
            _port = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Remote Path For FTP Account")> _
    Public Property RemotePath() As String
        Get
            Return _remotePath
        End Get
        Set(ByVal value As String)
            _remotePath = value
        End Set
    End Property
    <CategoryAttribute("FTP"), Description("Username For FTP Account")> _
    Public Property UserName() As String
        Get
            Return _userName
        End Get
        Set(ByVal value As String)
            _userName = value
        End Set
    End Property
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
    Public Sub New(ByVal Name As String, ByVal Host As String, ByVal UserName As String, Optional ByVal Password As String = "", Optional ByVal Port As Integer = 21, Optional ByVal RemotePath As String = "", Optional ByVal Passive As Boolean = False, Optional ByVal ExternalHost As String = "")
        Me.Name = Name
        Me.Host = Host
        Me.UserName = UserName
        Me.Password = Password
        Me.Passive = Passive
        Me.Port = Port
        Me.RemotePath = RemotePath
        Me.ExternalHost = ExternalHost
    End Sub
#End Region
End Class

''' <summary>
''' Collection of ftp settings
''' </summary>
''' <remarks></remarks>
Public Class ClassFTPSettings
    Inherits ObjectModel.KeyedCollection(Of String, ClassFTPSetting)
    Public Overloads Sub Add(ByVal Name As String, ByVal Host As String, ByVal UserName As String, Optional ByVal Password As String = "", Optional ByVal Port As Integer = 21, Optional ByVal RemotePath As String = "", Optional ByVal Passive As Boolean = False, Optional ByVal ExternalHost As String = "")
        Dim oClassFTPSetting As New ClassFTPSetting
        oClassFTPSetting.Name = Name
        oClassFTPSetting.Host = Host
        oClassFTPSetting.UserName = UserName
        oClassFTPSetting.Password = Password
        oClassFTPSetting.Passive = Passive
        oClassFTPSetting.Port = Port
        oClassFTPSetting.RemotePath = RemotePath
        oClassFTPSetting.ExternalHost = ExternalHost
        MyBase.Add(oClassFTPSetting)
    End Sub
    ''' <summary>
    ''' Save the Project
    ''' </summary>
    ''' <param name="filename">File name and path</param>
    ''' <remarks></remarks>
    Public Sub Save(ByVal filename As String)
        Dim mlSerializer As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(ClassFTPSetting))
        Dim writer As IO.StringWriter = New IO.StringWriter()
        mlSerializer.Serialize(writer, Me)
        My.Computer.FileSystem.WriteAllText(filename, writer.ToString, False, Global.System.Text.Encoding.Default)
    End Sub
    Protected Overrides Function GetKeyForItem(ByVal item As ClassFTPSetting) As String
        Return item.Name
    End Function
End Class
